package igor.mass.render.renderables;

import igor.mass.R;
import igor.mass.model.AndroidParam;
import android.content.Context;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class IntegerRenderable extends LinearLayout implements AndroidRenderable{
	AndroidParam param;
	TextView label;
	EditText textField;
	
	public IntegerRenderable(Context context, AndroidParam param, Object initialValue) {
		super(context);
		this.param = param;
		setBackgroundResource(R.color.background);
		setOrientation(LinearLayout.VERTICAL);
		setPadding(0, 8, 0, 8);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		
		label = new TextView(context);
		label.setText(param.name);
		label.setTextSize(18);
		label.setPadding(8, 6, 0, 6);
		label.setBackgroundResource(R.color.background);
		addView(label, params);
		
		textField = new EditText(context);
		textField.setInputType(InputType.TYPE_CLASS_NUMBER);
		textField.setText(initialValue.toString());
		addView(textField, params);
	}

	@Override
	public String getValue() {
		return textField.getText().toString();
	}
	
	@Override
	public View getView() {
		return this;
	}

}
